package com.asktgapp.user.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.asktgapp.JGTool.JGColor;
import com.asktgapp.JGTool.Utils;
import com.asktgapp.R;
import com.asktgapp.application.ApiUtil;
import com.asktgapp.application.Apiservice;
import com.asktgapp.architecture.retrofit.ApiException;
import com.asktgapp.architecture.retrofit.ApiResponseBody;
import com.asktgapp.architecture.rxjava.ExceptionHandle;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.engineer.activity.MyAnswerActivity;
import com.asktgapp.model.FreeAskSearchVO;
import com.asktgapp.modulebase.common.adapter.BaseAdapter;
import com.asktgapp.modulebase.common.adapter.BaseViewHolder;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.modulebase.common.util.Util;
import com.asktgapp.user.activity.FreeAskAnswerDetailActivity;
import com.asktgapp.user.activity.FreeAskPutQuestionsActivity;
import com.asktgapp.user.activity.FreeAskSearchActivity;
import com.asktgapp.utils.ImageDisplayUtil;
import com.asktgapp.widget.RefreshRecyclerView;
import com.yanzhenjie.recyclerview.swipe.widget.DefaultItemDecoration;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * time:2018/1/24
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:快速提问
 * 修改时间 2018年7月21日18:54:57
 */

public class FreeAskFragment extends BaseFragment {
    private TextView tvSearch, tvPutQuestions;
    private RefreshRecyclerView refreshRecyclerView;
    private RecyclerView mRecyclerView;
    private BaseAdapter mBaseAdapter;
    private int mPage = 1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_free_ask, container, false);
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {
        getBaseActivity().setBackNavigationIcon();
//        if (!PreferencesUtil.getBoolean(getActivity(), PreferencesUtil.KEY_IS_ENGINEER))
        setHasOptionsMenu(true);
        tvSearch = rootView.findViewById(R.id.tvSearch);
        tvPutQuestions = rootView.findViewById(R.id.tvPutQuestions);

        tvPutQuestions.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkIsLogin("登录后可查看更多内容"))
                    getActivity().startActivity(new Intent(getActivity(), FreeAskPutQuestionsActivity.class));
            }
        });
        tvSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().startActivity(new Intent(getActivity(), FreeAskSearchActivity.class));
            }
        });
        refreshRecyclerView = rootView.findViewById(R.id.recycleHot);
        mRecyclerView = refreshRecyclerView.getRecyclerView();
//        mRecyclerView = rootView.findViewById(R.id.recycleHot);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));

        mRecyclerView.addItemDecoration(new DefaultItemDecoration(JGColor.APP_BACKGROUND));
        refreshRecyclerView.setRefreshAction(new RefreshRecyclerView.Action() {
            @Override
            public void onAction(int page) {
                mPage = 1;
                selProbleList();
            }
        });
        refreshRecyclerView.setLoadMoreAction(new RefreshRecyclerView.Action() {
            @Override
            public void onAction(int page) {
                mPage = page;
                selProbleList();
            }
        });
        mBaseAdapter = new BaseAdapter(getActivity()) {
            @Override
            public BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
                BaseViewHolder holder;
                if (viewType == 0) {
                    holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_free_ask_hot, parent, false),
                            new BaseViewHolder.Callbacks2() {
                                @Override
                                public void bind(BaseViewHolder holder, Object data) {
                                    if (data instanceof FreeAskSearchVO) {
                                        final FreeAskSearchVO bean = (FreeAskSearchVO) data;


                                        LinearLayout allAnswer = holder.getView(R.id.llAnswerComment);
                                        ImageView askHead = holder.getView(R.id.iv_head_ask);
//                                    ImageView answerHead = holder.getView(R.id.iv_answer_head);
                                        ImageView ivZan = holder.getView(R.id.ivZan);

                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), askHead, bean.getUserPic());
                                        holder.setText(R.id.tvAskName, bean.getUsername());
                                        holder.setText(R.id.tvZan, bean.getProblemLikeNum());
                                        holder.setText(R.id.tv_answer, bean.getContent());
                                        TextView answerContent = holder.getView(R.id.tv_answer);
                                        answerContent.setMaxLines(3);
                                        Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                        String timeStr = Utils.getAskTime(date);
                                        holder.setText(R.id.addTime, timeStr);

                                        if (bean.getAnswerList().size() > 0) {
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.answerNumber, bean.getAnswerNum() + " 回复");
//                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), answerHead, bean.getUserPic());
                                            holder.setText(R.id.tvAnswerName, bean.getAnswerList().get(0).getUsername1());
                                            holder.setText(R.id.tvAnswerContent, bean.getAnswerList().get(0).getContent());
                                            //判断是否工程师
                                            if (bean.getAnswerList().get(0).getIsProjector().equals("1")) {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                            } else {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                            }
                                            if (bean.getAnswerList().size() > 1) {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.VISIBLE);
                                                holder.setText(R.id.tvAnswerName2, bean.getAnswerList().get(1).getUsername1());
                                                holder.setText(R.id.tvAnswerContent2, bean.getAnswerList().get(1).getContent());
                                                //判断是否工程师
                                                if (bean.getAnswerList().get(1).getIsProjector().equals("1")) {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.VISIBLE);
                                                } else {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.INVISIBLE);
                                                }
                                            } else {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                            }

                                        } else {
                                            holder.setText(R.id.answerNumber, "无回复");
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.GONE);
                                            holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                        }
                                        allAnswer.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(bean.getId(), getContext());
                                            }
                                        });
                                        if (TextUtils.isEmpty(bean.getLikeId()))
                                            ivZan.setImageResource(R.mipmap.zan_2);
                                        else {
                                            ivZan.setImageResource(R.mipmap.zan_1);
                                        }
                                        holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //点赞接口
                                                if (TextUtils.isEmpty(bean.getLikeId())) {
                                                    dealZan(bean.getId(), "1", bean);
                                                } else {
                                                    dealZan(bean.getId(), "0", bean);
                                                }
                                                index = mBaseAdapter.getItemIndex(bean);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onItemClick(BaseViewHolder holder, View view, int position) {
                                    FreeAskSearchVO b = (FreeAskSearchVO) mBaseAdapter.getData(position);
                                    FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(b.getId(), getContext());
                                }
                            });

                } else if (viewType == 1) {
                    holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_free_ask_img1, parent, false),
                            new BaseViewHolder.Callbacks2() {
                                @Override
                                public void bind(BaseViewHolder holder, Object data) {
                                    if (data instanceof FreeAskSearchVO) {
                                        final FreeAskSearchVO bean = (FreeAskSearchVO) data;


                                        LinearLayout allAnswer = holder.getView(R.id.llAnswerComment);
                                        ImageView askHead = holder.getView(R.id.iv_head_ask);
//                                    ImageView answerHead = holder.getView(R.id.iv_answer_head);
                                        ImageView ivZan = holder.getView(R.id.ivZan);
                                        ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);

                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), askHead, bean.getUserPic());
                                        holder.setText(R.id.tvAskName, bean.getUsername());
                                        holder.setText(R.id.tvZan, bean.getProblemLikeNum());
                                        holder.setText(R.id.tv_answer, bean.getContent());

                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getImgList().get(0));

                                        Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                        String timeStr = Utils.getAskTime(date);
                                        holder.setText(R.id.addTime, timeStr);

                                        if (bean.getAnswerList().size() > 0) {
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.answerNumber, bean.getAnswerNum() + " 回复");
//                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), answerHead, bean.getUserPic());
                                            holder.setText(R.id.tvAnswerName, bean.getAnswerList().get(0).getUsername1());
                                            holder.setText(R.id.tvAnswerContent, bean.getAnswerList().get(0).getContent());
                                            //判断是否工程师
                                            if (bean.getAnswerList().get(0).getIsProjector().equals("1")) {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                            } else {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                            }
                                            if (bean.getAnswerList().size() > 1) {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.VISIBLE);
                                                holder.setText(R.id.tvAnswerName2, bean.getAnswerList().get(1).getUsername1());
                                                holder.setText(R.id.tvAnswerContent2, bean.getAnswerList().get(1).getContent());
                                                //判断是否工程师
                                                if (bean.getAnswerList().get(1).getIsProjector().equals("1")) {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.VISIBLE);
                                                } else {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.INVISIBLE);
                                                }
                                            } else {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                            }

                                        } else {
                                            holder.setText(R.id.answerNumber, "无回复");
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.GONE);
                                            holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                        }
                                        allAnswer.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(bean.getId(), getContext());
                                            }
                                        });
                                        if (TextUtils.isEmpty(bean.getLikeId()))
                                            ivZan.setImageResource(R.mipmap.zan_2);
                                        else {
                                            ivZan.setImageResource(R.mipmap.zan_1);
                                        }
                                        holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //点赞接口
                                                if (TextUtils.isEmpty(bean.getLikeId())) {
                                                    dealZan(bean.getId(), "1", bean);
                                                } else {
                                                    dealZan(bean.getId(), "0", bean);
                                                }
                                                index = mBaseAdapter.getItemIndex(bean);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onItemClick(BaseViewHolder holder, View view, int position) {
                                    FreeAskSearchVO b = (FreeAskSearchVO) mBaseAdapter.getData(position);
                                    FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(b.getId(), getContext());
                                }
                            });

                } else if (viewType == 2) {
                    holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_free_ask_img2, parent, false),
                            new BaseViewHolder.Callbacks2() {
                                @Override
                                public void bind(BaseViewHolder holder, Object data) {
                                    if (data instanceof FreeAskSearchVO) {
                                        final FreeAskSearchVO bean = (FreeAskSearchVO) data;


                                        LinearLayout allAnswer = holder.getView(R.id.llAnswerComment);
                                        ImageView askHead = holder.getView(R.id.iv_head_ask);
//                                    ImageView answerHead = holder.getView(R.id.iv_answer_head);
                                        ImageView ivZan = holder.getView(R.id.ivZan);
                                        ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);
                                        ImageView ivQuestionImg2 = holder.getView(R.id.ivQuestionImg2);
                                        LinearLayout llQuestionImg = holder.getView(R.id.llQuestionImg);
                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), askHead, bean.getUserPic());
                                        holder.setText(R.id.tvAskName, bean.getUsername());
                                        holder.setText(R.id.tvZan, bean.getProblemLikeNum());
                                        holder.setText(R.id.tv_answer, bean.getContent());

                                        llQuestionImg.setVisibility(View.VISIBLE);
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg2, getActivity(), bean.getImgList().get(1));

                                        Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                        String timeStr = Utils.getAskTime(date);
                                        holder.setText(R.id.addTime, timeStr);

                                        if (bean.getAnswerList().size() > 0) {
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.answerNumber, bean.getAnswerNum() + " 回复");
//                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), answerHead, bean.getUserPic());
                                            holder.setText(R.id.tvAnswerName, bean.getAnswerList().get(0).getUsername1());
                                            holder.setText(R.id.tvAnswerContent, bean.getAnswerList().get(0).getContent());
                                            //判断是否工程师
                                            if (bean.getAnswerList().get(0).getIsProjector().equals("1")) {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                            } else {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                            }
                                            if (bean.getAnswerList().size() > 1) {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.VISIBLE);
                                                holder.setText(R.id.tvAnswerName2, bean.getAnswerList().get(1).getUsername1());
                                                holder.setText(R.id.tvAnswerContent2, bean.getAnswerList().get(1).getContent());
                                                //判断是否工程师
                                                if (bean.getAnswerList().get(1).getIsProjector().equals("1")) {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.VISIBLE);
                                                } else {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.INVISIBLE);
                                                }
                                            } else {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                            }

                                        } else {
                                            holder.setText(R.id.answerNumber, "无回复");
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.GONE);
                                            holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                        }
                                        allAnswer.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(bean.getId(), getContext());
                                            }
                                        });
                                        if (TextUtils.isEmpty(bean.getLikeId()))
                                            ivZan.setImageResource(R.mipmap.zan_2);
                                        else {
                                            ivZan.setImageResource(R.mipmap.zan_1);
                                        }
                                        holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //点赞接口
                                                if (TextUtils.isEmpty(bean.getLikeId())) {
                                                    dealZan(bean.getId(), "1", bean);
                                                } else {
                                                    dealZan(bean.getId(), "0", bean);
                                                }
                                                index = mBaseAdapter.getItemIndex(bean);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onItemClick(BaseViewHolder holder, View view, int position) {
                                    FreeAskSearchVO b = (FreeAskSearchVO) mBaseAdapter.getData(position);
                                    FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(b.getId(), getContext());
                                }
                            });
                } else {
                    holder = new BaseViewHolder(LayoutInflater.from(getActivity()).inflate(R.layout.item_free_ask_img3, parent, false),
                            new BaseViewHolder.Callbacks2() {
                                @Override
                                public void bind(BaseViewHolder holder, Object data) {
                                    if (data instanceof FreeAskSearchVO) {
                                        final FreeAskSearchVO bean = (FreeAskSearchVO) data;


                                        LinearLayout allAnswer = holder.getView(R.id.llAnswerComment);
                                        ImageView askHead = holder.getView(R.id.iv_head_ask);
//                                    ImageView answerHead = holder.getView(R.id.iv_answer_head);
                                        ImageView ivZan = holder.getView(R.id.ivZan);
                                        ImageView ivQuestionImg1 = holder.getView(R.id.ivQuestionImg1);
                                        ImageView ivQuestionImg2 = holder.getView(R.id.ivQuestionImg2);
                                        ImageView ivQuestionImg3 = holder.getView(R.id.ivQuestionImg3);
                                        LinearLayout llQuestionImg = holder.getView(R.id.llQuestionImg);
                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), askHead, bean.getUserPic());
                                        holder.setText(R.id.tvAskName, bean.getUsername());
                                        holder.setText(R.id.tvZan, bean.getProblemLikeNum());
                                        holder.setText(R.id.tv_answer, bean.getContent());

                                        llQuestionImg.setVisibility(View.VISIBLE);

                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg1, getActivity(), bean.getImgList().get(0));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg2, getActivity(), bean.getImgList().get(1));
                                        ImageDisplayUtil.LoadASKIMG(ivQuestionImg3, getActivity(), bean.getImgList().get(2));


                                        Date date = Util.StrToDate(bean.getAddTime(), "yyyy.MM.dd HH:mm:ss");
                                        String timeStr = Utils.getAskTime(date);
                                        holder.setText(R.id.addTime, timeStr);

                                        if (bean.getAnswerList().size() > 0) {
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.VISIBLE);
                                            holder.setText(R.id.answerNumber, bean.getAnswerNum() + " 回复");
//                                        ImageDisplayUtil.loadCircleHeadImage(getActivity(), answerHead, bean.getUserPic());
                                            holder.setText(R.id.tvAnswerName, bean.getAnswerList().get(0).getUsername1());
                                            holder.setText(R.id.tvAnswerContent, bean.getAnswerList().get(0).getContent());
                                            //判断是否工程师
                                            if (bean.getAnswerList().get(0).getIsProjector().equals("1")) {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.VISIBLE);
                                            } else {
                                                holder.getView(R.id.tvCommentType).setVisibility(View.INVISIBLE);
                                            }
                                            if (bean.getAnswerList().size() > 1) {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.VISIBLE);
                                                holder.setText(R.id.tvAnswerName2, bean.getAnswerList().get(1).getUsername1());
                                                holder.setText(R.id.tvAnswerContent2, bean.getAnswerList().get(1).getContent());
                                                //判断是否工程师
                                                if (bean.getAnswerList().get(1).getIsProjector().equals("1")) {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.VISIBLE);
                                                } else {
                                                    holder.getView(R.id.tvCommentType2).setVisibility(View.INVISIBLE);
                                                }
                                            } else {
                                                holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                            }

                                        } else {
                                            holder.setText(R.id.answerNumber, "无回复");
                                            holder.getView(R.id.llAnswerComment).setVisibility(View.GONE);
                                            holder.getView(R.id.llAnswer2).setVisibility(View.GONE);
                                        }
                                        allAnswer.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(bean.getId(), getContext());
                                            }
                                        });
                                        if (TextUtils.isEmpty(bean.getLikeId()))
                                            ivZan.setImageResource(R.mipmap.zan_2);
                                        else {
                                            ivZan.setImageResource(R.mipmap.zan_1);
                                        }
                                        holder.getView(R.id.zan).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //点赞接口
                                                if (TextUtils.isEmpty(bean.getLikeId())) {
                                                    dealZan(bean.getId(), "1", bean);
                                                } else {
                                                    dealZan(bean.getId(), "0", bean);
                                                }
                                                index = mBaseAdapter.getItemIndex(bean);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onItemClick(BaseViewHolder holder, View view, int position) {
                                    FreeAskSearchVO b = (FreeAskSearchVO) mBaseAdapter.getData(position);
                                    FreeAskAnswerDetailActivity.startFreeAskAnswerDetailActivty(b.getId(), getContext());
                                }
                            });
                }
                return holder;
            }

            @Override
            public int getItemViewType(int position) {
                FreeAskSearchVO b = (FreeAskSearchVO) mBaseAdapter.getData().get(position);
                if (b.getImgList().size() == 1)
                    return 1;
                if (b.getImgList().size() == 2)
                    return 2;
                if (b.getImgList().size() == 3)
                    return 3;
                if (b.getImgList().size() == 0)
                    return 0;
                return super.getItemViewType(position);
            }
        };
        mRecyclerView.setAdapter(mBaseAdapter);

    }

    @Override
    public void loadData() {
//        selProbleList();
    }

    boolean isShow = true;

    @Override
    public void onResume() {
        super.onResume();
        selProbleList();

    }

    private void selProbleList() {
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();
        params.put("userId", PreferencesUtil.getString(getContext(), PreferencesUtil.USER_ID));
        params.put("page", mPage);
        params.put("isHot", "0");
        if (isShow) {
            visibleLoading();
            isShow = false;
        }
        Call<ApiResponseBody<List<FreeAskSearchVO>>> call = apiservice.selProbleList(params);
        call.enqueue(new Callback<ApiResponseBody<List<FreeAskSearchVO>>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<List<FreeAskSearchVO>>> call, Response<ApiResponseBody<List<FreeAskSearchVO>>> response) {

                inVisibleLoading();
                if (response.isSuccessful()) {
                    List<FreeAskSearchVO> bean = response.body().getResult();
//                    if (bean != null && bean.size() > 0) {
//                        mBaseAdapter.setData(bean);
//                    }
                    if (mPage == 1) {
                        if (bean.size() == 0) {
                            visibleNoData();
                        } else {
                            mBaseAdapter.setData(bean);
                            refreshRecyclerView.showNextMore(mPage);
                        }
                    } else {
                        if (bean.size() == 0) {
                            refreshRecyclerView.showNoMore();
                        } else {
                            mBaseAdapter.addData(BaseAdapter.AddType.LASE, bean);
                            refreshRecyclerView.showNextMore(mPage);
                        }
                    }
                } else {
                    showTost(response.raw().message(), 1);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<List<FreeAskSearchVO>>> call, Throwable t) {

                inVisibleLoading();
                if (refreshRecyclerView == null) {
                    Log.i("JGAPP", "mRefreshRecyclerView == null");
                    return;
                }
                refreshRecyclerView.endPage();
                ApiException apiException = ExceptionHandle.handleException(t);
                if (apiException.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (apiException.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(apiException.getMessage(), 0);
                }
            }
        });
    }

    private int index = -1;

    //点赞接口
    private void dealZan(String id, final String temp, final FreeAskSearchVO bean) {
        if (Util.isEmpty(PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID))) {
            showTost("未登录，不能点赞！请先登录", 1);
            return;
        }
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();

        params.put("temp", temp);
        params.put("type", 2);
        params.put("id", id);
        params.put("userid", PreferencesUtil.getString(getActivity(), PreferencesUtil.USER_ID));
//        showProgress(getClass().getSimpleName());
        Call<ApiResponseBody> call = apiservice.doLike(params);
        call.enqueue(new Callback<ApiResponseBody>() {
            @Override
            public void onResponse(Call<ApiResponseBody> call, Response<ApiResponseBody> response) {
//                dismissProgress();
                if (response.isSuccessful()) {
                    int num = Integer.valueOf(bean.getProblemLikeNum());
                    if (temp.equals("1")) {
                        num++;
                        bean.setLikeId("13");
                    } else {
                        num--;
                        bean.setLikeId(null);
                    }
                    bean.setProblemLikeNum(String.valueOf(num));
                    mBaseAdapter.update(bean, index);
                } else {
                    showTost(response.raw().message(), 0);
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody> call, Throwable t) {
//                dismissProgress();
                ApiException exception = ExceptionHandle.handleException(t);
                if (exception.isTokenInvalid()) {
                    showUnLoginSnackbar();
                } else if (exception.isNetConnected()) {
                    showSetNetworkSnackbar();
                } else {
                    showTost(exception.getMessage(), 1);
                }
            }
        });

    }


    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.my_answer, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        startActivity(new Intent(getActivity(), MyAnswerActivity.class));
        return super.onOptionsItemSelected(item);
    }
}
